
package pluginInterfaces;

import java.util.List;

import modelInterfaces.IEvent;
import modelInterfaces.IPrediction;

/**
 * Abstract class for compute value in classification metrics. 
 * 
 * @author Andy Cullache
 */
public abstract class IPluginClassificationMetric implements IPluginMetric {

	/**
	 * Determines the overlap between the training set and test set and then apply the method computeAccuracy () 
	 * and return the value of the application of the metric.
	 * 
	 * @param hiddenEvents      Test set.
	 * @param recommendations      Prediction from recommendation algorithm.
	 * @return      Application value of the metric.
	 */
    public double accuracy(List<IEvent> hiddenEvents, List<IPrediction> recommendations){
    	int correctRecommendations = 0;
    	for(IPrediction prediction : recommendations){
    		for(IEvent event : hiddenEvents){
    			if(prediction.getObject().getId() == Integer.parseInt(event.getObject())){
    				correctRecommendations++;
    			}
            }
    	}
        return this.computeAccuracy(hiddenEvents, recommendations, correctRecommendations);
    }

    /**
     * Method to implement from metric plugin, compute the accuracy of apply metric.
     * 
     * @param hiddenEvents      Test set.
	 * @param recommendations      Prediction from recommendation algorithm.
	 * @param correct      Items "hit", coincidence between test set and recommendations of the algorithm.
     * @return      Application value of the metric.
     */
    public abstract double computeAccuracy(List<IEvent> hiddenEvents, List<IPrediction> recommendation, int correct);
    
    /**
     * Method that return the metric name.
     */
    public abstract String toString();
    
}
